package com.ourhealth.controller;

import com.ourhealth.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ych
 * @version v1.0
 * @date 2019/12/3 16:30
 * @description
 **/
@RestController
@RequestMapping("/user")
public class UserController {


    @RequestMapping("/getUserName")
    public Result getUserName(){
        //从springsecurity上下文获取用户名
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return new Result(true,"",user.getUsername());
    }
}